<?php
namespace App\Http\Controllers\Web;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;

/**
 * 后台登录
 * Class LoginController
 * @package App\Http\Controllers\Web
 */
class LoginController extends Controller {

    public function login() {
        return view('login.login');
    }

    public function loginSubmit(Request $request)
    {
        $this->validate($request, [
            'username' => 'required',
            'password' => 'required',
        ], [
            'username.required' => '请输入登陆用户名',
            'password.required' => '请输入登陆密码',
        ]);

        if (!Auth::guard('admin')->attempt(['username' => $request->input('username'), 'password' => $request->input('password')], $request->input('remember'))) {
            return back()->withErrors(['用户名或密码错误']);
        }
        return redirect('/admin');
    }

    public function logout(Request $request) {
        Auth::logout();
        return Redirect::route('login');
    }

}